﻿using System;

namespace ARS.Control.Custom.Entity.Fields
{
    public class Field:Attribute
    {
        /// <summary>
        /// 默认值
        /// </summary>
        public string DefaultValue
        {
            get;
            set;
        }

        
        private object _value;
        /// <summary>
        /// 属性值,不能通过此设置默认值
        /// </summary>
        public object Value
        {
            get
            {
                if (_value == null)
                {
                    if (this.Widget != null)
                    {
                        _value = this.Widget.GetInputValue();
                    }
                }
                return _value;
            }
            set { _value = value; }
        }
        
        public T GetValue<T>()
        {
            return (T)Value;
            //return t;
        }

        /// <summary>
        /// 显示名称
        /// </summary>
        public string Verbose_Name
        {
            get;
            set;
        }
        /// <summary>
        /// 帮助信息
        /// </summary>
        public string Help_Text
        {
            get;
            set;
        }
        /// <summary>
        /// 显示控件
        /// </summary>
        public virtual ARS.Control.Custom.Entity.Forms.Form Widget
        {
            get;
            set;
        }
        /// <summary>
        /// 数据库字段名
        /// </summary>
        public string Db_Field_Name
        {
            get;
            set;
        }

        private string _Html_Control_Name;
        public string Html_Control_Name
        {
            get
            {
                return _Html_Control_Name;
            }
            set
            {
                _Html_Control_Name = value;
            }
        }
        /// <summary>
        /// 是否唯一
        /// </summary>
        public bool IsUnique
        {
            get;
            set;
        }
        /// <summary>
        /// 唯一的条件
        /// </summary>
        public string UniqueWhere
        {
            get;
            set;
        }

        private bool _isAllowAdd = true;
        /// <summary>
        /// 是否添加
        /// </summary>
        public bool IsAllowAdd
        {
            get
            {
                return _isAllowAdd;
            }
            set
            {
                _isAllowAdd = value;
            }
        }

        private bool _isAllowUpdate = true;
        /// <summary>
        /// 是否修改
        /// </summary>
        public bool IsAllowUpdate
        {
            get
            {
                return _isAllowUpdate;
            }
            set
            {
                _isAllowUpdate = value;
            }
        }

        private bool _IsAllowBlank = true;
        /// <summary>
        /// 允许值为空
        /// </summary>
        public bool IsAllowBlank
        {
            get
            {
                return _IsAllowBlank;
            }
            set
            {
                _IsAllowBlank = value;
            }
        }

        private int _rank = 100;
        /// <summary>
        /// 控件在页面显示排序，从小到大依次排序
        /// </summary>
        public int Rank
        {
            get { return _rank; }
            set { _rank = value; }
        }

        private bool _Visible=true;
        /// <summary>
        /// 是否显示控件
        /// </summary>
        public bool Visible
        {
            get
            {
                return _Visible;
            }
            set
            {
                _Visible = value;
            }
        }
        /// <summary>
        /// 显示数据
        /// </summary>
        public bool IsShow
        {
            get;
            set;
        }

        private bool _isSaveDb=true;
        /// <summary>
        /// 是否保存到数据库
        /// </summary>
        public bool IsSaveDb
        {
            get
            {
                return _isSaveDb;
            }
            set
            {
                _isSaveDb = value;
            }
        }
        /// <summary>
        /// css名字
        /// </summary>
        public string CssName
        {
            get;
            set;
        }

        /// <summary>
        /// 宽
        /// </summary>
        public double Width { get; set; }
        /// <summary>
        /// 高
        /// </summary>
        public double Height { get; set; }


        private int _rankList = 100;
        /// <summary>
        /// 列表排序
        /// </summary>
        public int RankList
        {
            get { return _rankList; }
            set { _rankList = value; }
        }
        /// <summary>
        /// 搜索排序
        /// </summary>
        public int RankSearch { get; set; }
        /// <summary>
        /// 查询条件，{0}代表值
        /// </summary>
        public string SearchSql { get; set; }

        /// <summary>
        /// 列表显示
        /// </summary>
        public bool IsListShow { get; set; }

        /// <summary>
        /// 输入正则
        /// </summary>
        public string RegexStr
        {
            get;
            set;
        }
        /// <summary>
        /// 最长
        /// </summary>
        public int MaxLength { get; set; }

        /// <summary>
        /// 最短
        /// </summary>
        public int MinLength { get; set; }

        /// <summary>
        /// 输入错误提示
        /// </summary>
        public string Tip
        {
            get;
            set;
        }
        /// <summary>
        /// 是否是Url显示字段
        /// </summary>
        public bool IsUrlField { get; set; }

        public virtual string GetTip()
        {

            return Tip;
        }
    }
}
